#if defined _td_natives_included
	#endinput
#endif

#define _td_natives_included

new const gStandardNatives[17][] = {
	"register_dealer",
	"register_dealer_by_id",
	"set_dealer_item_def",
	"get_dealers_count",
	"get_items_count",
	
	"is_dealer_registered",
	"give_items_to_dealers",
	"give_items_to_dealer",
	"give_item_to_dealer",
	"clear_player_dealers",
	
	"set_player_dealers",
	"set_player_dealer",
	"clear_player_items",
	"set_player_items",
	"set_player_item",
	
	"dealer_menu",
	"item_menu"
}
/*

	This method registeres standard natives.
	Should be called in plugin_natives
*/
stock register_def_natives(){
	
	new count = sizeof(gStandardNatives);
	
	for(new i=0;i<count;i++) 
		register_def_native(i);
}

stock register_def_native(i){
	new nat[32];
	new name[64];
	new len = charsmax(name);
	nat[0] = '^0';
	formatex(nat, 31, "_%s", gStandardNatives[i]);
	name[0] = '^0';
	formatex(name, len, "%s_%s", prefix, nat);
	register_native(name, nat);
}

public _register_dealer(iPlugin, iParams){
	new name[MAX_DEALER_NAME_LEN];
	get_string(1, name, MAX_DEALER_NAME_LEN -1);
	new DealerRefreshAction:action = DealerRefreshAction:get_param(2);
	new refreshItemsCount = get_param(3);
	new bool:refreshItemsDropOld = bool:get_param(4);
	
	return td_register_dealer( name, action, refreshItemsCount,refreshItemsDropOld);
}

public _register_dealer_by_id(iPlugin, iParams){	
	new id = get_param(1);
	new name[MAX_DEALER_NAME_LEN];
	new DealerRefreshAction:action = DealerRefreshAction:get_param(3);
	new refreshItemsCount = get_param(4);
	new bool:refreshItemsDropOld = bool:get_param(5);
	
	return td_register_dealer_by_id(id, name, action, refreshItemsCount,refreshItemsDropOld);
}


public _set_dealer_item_def(iPlugin, iParams){
	new dealer = get_param(1);
	new item = get_param(2);
	new iMinCount = max(0, get_param(3));
	new iMaxCount= max(iMinCount, get_param(4));
	
	new iMinChance = clamp(get_param(5), 0, 100);
	new iMaxChance =  clamp(get_param(6), iMinChance, 100);
		
	new iMinCost = max(0, get_param(7));
	new iMaxCost = max(iMinCost, get_param(8));
	
	td_set_dealer_item_def( dealer, item, iMinCount, iMaxCount, iMinChance, iMaxChance, iMinCost, iMaxCost);
}

public  _get_dealers_count(iPlugin, iParams){
	new count = 0;
	for(new id = 0;id<MAX_DEALERS; id++) 
		if(gDealerDef[id][Di_Registered])
			count++;
	return count;
}
public _get_items_count(iPlugin, iParams){
	return Items;
}
public _is_dealer_registered(iPlugin, iParams){	
	new id = get_param(1);
	if(id< MAX_DEALERS )
		return gDealerDef[id][Di_Registered];
	return 0;
}

public _give_items_to_dealers(iPlugin, iParams){
	new bool:forceGive = bool:get_param(1);
	new bool:forceDropOld = bool:get_param(2);
	
	td_give_items_to_dealers(forceGive, forceDropOld);
}
public _give_items_to_dealer(iPlugin, iParams){
	new dealer = get_param(1);
	new bool:forceGive = bool:get_param(2);
	new bool:forceDropOld = bool:get_param(3);
	
	td_give_items_to_dealer(dealer, forceGive, forceDropOld);
}

public _give_item_to_dealer(iPlugin, iParams){
	new dealer = get_param(1);
	new item = get_param(2);
	new bool:bAdd = bool:get_param(3);
	new count = get_param(4);
	new cost = get_param(5);
	
	td_give_item_to_dealer(dealer, item, bAdd, count, cost);
}


public _clear_player_dealers(iPlugin, iParams){
	new id = get_param(1);
	td_set_player_dealers(id, false);
}

public _set_player_dealers(iPlugin, iParams){
	new id = get_param(1);
	new dealers[MAX_DEALERS];
	new len = min(MAX_DEALERS , get_param(3));
	new clear = get_param(4);
	if(clear)
		td_set_player_dealers(id, false);
	get_array(2, dealers, len);
	for(new i=0;i<len;i++) 
		playerAvailableDealers[id][dealers[i]] = 1;
}

public _set_player_dealer(iPlugin, iParams){
	new id = get_param(1);
	new dealer = get_param(2);
	new bool:set = bool:get_param(3);
	
	playerAvailableDealers[id][dealer] = set;
}

public _clear_player_items(iPlugin, iParams){
	new id = get_param(1);
	
	td_set_player_items(id, false);
}
public _set_player_items(iPlugin, iParams){
	new id = get_param(1);
	new items[Items];
	new len = min(Items , get_param(3));
	get_array(2, items, len);
	new clear = get_param(4);
	
	if(clear) 
		td_set_player_items(id, false);
	
	
	for(new i=0;i<len;i++) 
		playerAvailableItems[id][items[i]] = 1;
}


public _set_player_item(iPlugin, iParams) {
	new id = get_param(1);
	new item = get_param(2);
	new set = get_param(3);
	
	playerAvailableItems[id][item] = set;
}



public _dealer_menu(iPlugin, iParams){
	new id = get_param(1);
	td_dealers_menu(id);
}

public _item_menu(iPlugin, iParams){
	new id=get_param(1);
	td_item_menu(id);
}
